//
//  SubjectSecondTableViewCell.m
//  ITrip
//
//  Created by dllo on 15/5/25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SubjectSecondTableViewCell.h"

@implementation SubjectSecondTableViewCell


- (void) dealloc{

    [_titleLabel release];
    [_titleIcon release];
    [_nameLabel release];
    [_imageView_ release];
    [_imageTitleLabel release];
    [_descriptionLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}


///创建cell
- (void) createCell{
    self.imageView_ = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageView_];
    [self.imageView_ release];
    
    self.titleIcon = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleIcon];
    [self.titleIcon release];

    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    
    self.descriptionLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.descriptionLabel];
    [self.descriptionLabel release];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.imageView_ addSubview:self.nameLabel];
    [self.nameLabel release];
    
    
    self.imageTitleLabel = [[UILabel alloc] init];
    [self.imageView_ addSubview:self.imageTitleLabel];
    [self.imageTitleLabel release];
    
}

- (void) setSubjectSecondModel:(SubjectSecondModel *)subjectSecondModel{
   
   

    ///给对象赋值
    _subjectSecondModel = subjectSecondModel;
    
    ///图片
    [self.imageView_ setImageWithURL: [NSURL URLWithString:subjectSecondModel.image_url] placeholderImage:nil];
    
    ///有标题的标题位置
    if (subjectSecondModel.title != nil && subjectSecondModel.title.length != 0) {
        self.titleLabel.frame = CGRectMake(45, 10, self.contentView.frame.size.width - 20, 35);
        ///标题赋值
        self.titleLabel.text = subjectSecondModel.title;
        self.titleLabel.textColor = [UIColor blackColor];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        //加标题图标
        self.titleIcon.frame = CGRectMake(10, 10, 32, 32);
        self.titleIcon.image = [UIImage imageNamed:@"iconfont-title"];
        
        ///有标题的图片位置
        if (subjectSecondModel.image_url != nil && subjectSecondModel.image_url.length != 0) {
            self.imageView_.frame = CGRectMake(10, 50, self.contentView.frame.size.width - 20, (self.contentView.frame.size.width - 20) * (subjectSecondModel.image_height  / (CGFloat)subjectSecondModel.image_width));
            ///图片
            [self.imageView_ setImageWithURL: [NSURL URLWithString:subjectSecondModel.image_url] placeholderImage:[UIImage imageNamed:@"defaultPicture"]];
            
            ///图片上旅行地名字
            self.imageTitleLabel.frame =CGRectMake(20, self.imageView_.frame.size.height - 40, 300, 25);
            self.imageTitleLabel.text = [subjectSecondModel.note objectForKey:@"trip_name"];
            self.imageTitleLabel.font = [UIFont systemFontOfSize:15];
            self.imageTitleLabel.textColor = [UIColor whiteColor];
            
            ///作者名字
            self.nameLabel.frame = CGRectMake(20, self.imageView_.frame.size.height - 80, 300, 25);
            self.nameLabel.text = [subjectSecondModel.note objectForKey:@"user_name"];
            self.nameLabel.font = [UIFont systemFontOfSize:15];
            self.nameLabel.textColor = [UIColor whiteColor];

            
            ///有标题有图片的文字位置
            if (subjectSecondModel.descriptions != nil && subjectSecondModel.descriptions.length != 0) {
                self.descriptionLabel.frame = CGRectMake(10, 50 + (self.contentView.frame.size.width - 20) * (subjectSecondModel.image_height  / (CGFloat)subjectSecondModel.image_width), self.contentView.frame.size.width - 20, 40);
                ///正文赋值
                self.descriptionLabel.text = subjectSecondModel.descriptions;
                self.descriptionLabel.textColor = [UIColor blackColor];
                self.descriptionLabel.font = [UIFont systemFontOfSize:15];
                self.descriptionLabel.numberOfLines = 500;
                [self.descriptionLabel sizeToFit];
            }
            ///有标题无图片的文字位置
        } else if (subjectSecondModel.descriptions != nil && subjectSecondModel.descriptions.length != 0) {
            self.descriptionLabel.frame = CGRectMake(10, 45, self.contentView.frame.size.width - 20, 40);
            ///正文赋值
            self.descriptionLabel.text = subjectSecondModel.descriptions;
            self.descriptionLabel.textColor = [UIColor blackColor];
            self.descriptionLabel.font = [UIFont systemFontOfSize:15];
            self.descriptionLabel.numberOfLines = 1000;
            [self.descriptionLabel sizeToFit];
        }
    }
    ///无标题的图片位置
    if ((subjectSecondModel.title == nil || subjectSecondModel.title.length == 0) && subjectSecondModel.image_url != nil && subjectSecondModel.image_url.length != 0) {
        
        self.imageView_.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, (self.contentView.frame.size.width - 20) * (subjectSecondModel.image_height  / (CGFloat)subjectSecondModel.image_width));
        
        [self.imageView_ setImageWithURL: [NSURL URLWithString:subjectSecondModel.image_url] placeholderImage:[UIImage imageNamed:@"defaultPicture"]];
        
        
        ///图片上旅行地名字
        self.imageTitleLabel.frame =CGRectMake(20, self.imageView_.frame.size.height - 40, 300, 25);
        self.imageTitleLabel.text = [subjectSecondModel.note objectForKey:@"trip_name"];
        self.imageTitleLabel.font = [UIFont systemFontOfSize:15];
        self.imageTitleLabel.textColor = [UIColor whiteColor];
        
        ///作者名字
        self.nameLabel.frame = CGRectMake(20, self.imageView_.frame.size.height - 80, 300, 25);
        self.nameLabel.text = [subjectSecondModel.note objectForKey:@"user_name"];
        self.nameLabel.font = [UIFont systemFontOfSize:15];
        self.nameLabel.textColor = [UIColor whiteColor];
        
        ///无标题有图片的文字位置
        if (subjectSecondModel.descriptions != nil && subjectSecondModel.descriptions.length != 0){
            
            self.descriptionLabel.frame = CGRectMake(10, (self.contentView.frame.size.width - 20) * (subjectSecondModel.image_height  / (CGFloat) subjectSecondModel.image_width) + 20, self.contentView.frame.size.width - 20, 40);
            ///正文赋值
            self.descriptionLabel.text = subjectSecondModel.descriptions;
            self.descriptionLabel.textColor = [UIColor blackColor];
            self.descriptionLabel.font = [UIFont systemFontOfSize:15];
            self.descriptionLabel.numberOfLines = 1000;
            [self.descriptionLabel sizeToFit];
            
        }
        
    }
    ///无标题无图片有文字
    if ((subjectSecondModel.title == nil || subjectSecondModel.title.length == 0) && (subjectSecondModel.image_url == nil || subjectSecondModel.image_url.length == 0) && subjectSecondModel.descriptions != nil && subjectSecondModel.descriptions.length != 0) {
        
        self.descriptionLabel.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, 40);
        ///正文赋值
        self.descriptionLabel.text = subjectSecondModel.descriptions;
        self.descriptionLabel.textColor = [UIColor blackColor];
        self.descriptionLabel.font = [UIFont systemFontOfSize:15];
        self.descriptionLabel.numberOfLines = 500;
        [self.descriptionLabel sizeToFit];
    }
    
 
    
//方法的括号
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
